home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Chassis 6.0 ƒ / ReadIntoTE.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  1.5 KB  |  38 lines  |  [TEXT/KAHL]

  1. /************************************************************************************/
  2. /*    ReadIntoTE                                                                        */
  3. /*                                                                                    */
  4. /*    Reads open file into existing TextEdit record                                    */
  5. /************************************************************************************/
  6.  
  7. #include "MyHeaders.h"
  8.  
  9. long ReadIntoTE(short pathRefNum, TEHandle hTE)
  10. {
  11.     long    byteCount = 256;                    /* bytes requested / returned        */
  12.     OSErr    readErr;                            /* return from I/O routines            */
  13.     long    bytesRead = 0;                        /* total of bytes returned            */
  14.     Ptr        beginP;                                /* ptr to begin of temp I/O area    */
  15.     Ptr        nextP;                                /* ptr to next avail pos in I/O ara    */
  16.  
  17.     CursorSelect (NIL, NIL, watchCursor);        /* set watch cursor                    */
  18.     
  19.     readErr = SetFPos (pathRefNum, fsFromStart, 0);    /* position file ptr to begin    */
  20.     
  21.     beginP = NewPtr(32767);                        /* get a temporary I/O area            */
  22.     nextP = beginP;                                /* next avail pos is at top            */
  23.     
  24.     readErr = noErr;                            /* initialize before read loop        */
  25.     while (readErr == noErr)                    /* read till error or EOF            */
  26.         {
  27.         readErr = FSRead (pathRefNum, &byteCount, nextP);    /* read a block            */
  28.         bytesRead += byteCount;                                /* add bytes to total    */
  29.         nextP += byteCount;                                    /* reset nxt avail pos    */
  30.         }
  31.  
  32.     TESetText (beginP, bytesRead, hTE);            /* copy into TE record                */
  33.     TESetSelect (0, 0, hTE);                    /* set selection at top                */
  34.  
  35.     DisposPtr (beginP);                            /* release temporary I/O area        */
  36.     
  37.     return bytesRead;                            /* return total no of bytes            */
  38. }